<?php
/**
 * https://gitee.com/Mao02
 * http://www.dazhetu.cn/
 * jay_fun 410136330@qq.com
 * Date: 2018/11/9 0009
 * Time: 下午 9:18
 */

namespace app\blog\controller;


use think\Controller;
use think\Request;
use think\Validate;

class Reply extends Controller
{
    public function commit(Request $request)
    {
        $data = $request->post();
        $rule = [
            'name'=>'require',
            'qq'=>'number|require',
            'website'=>'url|require',
            'content'=>'print|require',
            'article_id'=>'number|require',
            '__token__'=>'token'
        ];
        $message = [
            'name.require'=>'请输入姓名',
            'qq.require'=>'请输入QQ',
            'qq.number'=>'请输入QQ',
            'website.require'=>'请输入个人主页',
            'website.url'=>'请输入个人主页',
            'content.require'=>'请输入评论',
            'content.print'=>'请输入评论',
            'article_id.require'=>'非法访问',
            'article_id.number'=>'非法访问',
        ];
        $vali = new Validate($rule,$message,$data);
        if (!$vali->check($data)){
            $this->error($vali->getError());
        }
        $reply = new \app\common\model\content\Reply($data);
        $reply->create_time = $request->time();
        $reply->ip = $request->ip();
        $reply->state = 0;
        if (!$reply->save()){
            $this->error('操作失败！');
        }
        $this->success('操作成功！');
    }
}